/// ref: https://locka99.gitbooks.io/a-guide-to-porting-c-to-rust/content/features_of_rust/structs.html
///

pub fn cpp_cmp_demo() {
  test1();
}

fn test1() {
  let mut increment = Incrementor { value: &mut 1 };
  increment.increment();
}

struct Incrementor<'a> {
  value: &'a mut i32,
}

impl<'a> Incrementor<'a> {
  pub fn increment(&mut self) -> i32 {
    *self.value += 1;
    *self.value
  }
}

fn test2() {
  #[derive(Debug)]
  struct Data {
    data: Box<[u8; 100]>,
  }
  // ...
  // let v1 = Data { data: Box::new([0u8; 100])};
  // let v2 = v1;
  // ...

  {
    let v1 = Data {
      data: Box::new([0u8; 100]),
    };
    let ref v1_ref = &v1;
    we_own_it(&v1);
    println!("v = {:?}", &v1_ref);
  }
  fn we_own_it(v: &Data) {
    // ...
  }
}

fn test4() {
  {
    let mut v = Vec::new(); // empty vector
    fill_vector(&mut v);
    fill_vector(&mut v);
    // ...
    println!("Vector contains {:?}", v);
  }
  //...
  fn fill_vector(v: &mut Vec<i32>) {
    v.push(1);
    v.push(2);
    v.push(3);
  }
}

fn test5() {
  let mut x = 0;
  while x < 10 {
    x = x + 1;
  }
  let y = 10;
  let do_compare = true;
  if do_compare && x == y {
    println!("They match!");
  }
}
